//
//  RHPublicEditViewController.m
//  RuiHeAppApp
//
//  Created by Jun on 2023/7/20.
//

#import "RHPublicEditViewController.h"

@interface RHPublicEditViewController ()
@property(nonatomic,strong)UITextField *textField;
@end

@implementation RHPublicEditViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.view setBackgroundColor:CFTabViewBgColor];
    [self setupUI];
}



- (void)setupUI{
    
    UIView *bgView = [[UIView alloc] init];
    [bgView setBackgroundColor:UIColor.whiteColor];
    [self.view addSubview:bgView];
    
    QMUITextField *textField = [[QMUITextField alloc] init];
    textField.placeholder = @"请输入".rh_localized;
    [textField setFont:[UIFont systemFontOfSize:16]];
    [textField setTextColor:kCOLOR_HEX(@"3F4443")];
    [textField setClearButtonMode:UITextFieldViewModeWhileEditing];
    textField.text = self.content;
    textField.textInsets = UIEdgeInsetsMake(0, 10, 0, 0);
    [bgView addSubview:textField];
    self.textField = textField;
    if([self.key isEqualToString:@"nickName"]){
        textField.placeholder = @"请输入昵称".rh_localized;
    }
    if([self.key isEqualToString:@"address"]){
        textField.placeholder = @"请输入地址".rh_localized;
    }
    if([self.key isEqualToString:@"phonenumber"]){
        textField.placeholder = @"请输入电话号码".rh_localized;
        textField.maximumTextLength = 16;
        textField.keyboardType = UIKeyboardTypePhonePad;
    }
    [bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.top.mas_offset(10);
        make.height.mas_equalTo(50);
    }];
    
    [textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.insets(UIEdgeInsetsMake(5, 10, 5, 10));
    }];
    
    if(self.idx == 1||self.idx == 2){
        textField.maximumTextLength = 32;
    }
    if(self.idx == 3){
        textField.maximumTextLength = 64;
    }
        
        
    kWeakSelf;
    QMUIButton *sure = [QMUIButton buttonWithType:UIButtonTypeCustom];
    sure.frame = CGRectMake(0, 0, 40, 40);
    [sure setTitle:@"确定".rh_localized forState:UIControlStateNormal];
    [sure setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [[sure rac_signalForControlEvents:UIControlEventTouchUpInside]subscribeNext:^(__kindof UIControl * _Nullable x) {
        if(weakSelf.textField.text.length>0){
            
            [weakSelf.editInfoDic setObject:weakSelf.textField.text forKey:weakSelf.key];
            if(weakSelf.selectBlock){
                weakSelf.selectBlock(weakSelf.idx);
            }
        }
        [weakSelf.navigationController popViewControllerAnimated:YES];
    }];
    UIBarButtonItem *rightBtn = [[UIBarButtonItem alloc]initWithCustomView:sure];
    self.navigationItem.rightBarButtonItem = rightBtn;
}

@end
